function Keys()
{
    this.right = false;
    this.left  = false;
    this.up    = false;
    this.down  = false;

    this.clean = function()
    {
        this.right = false;
        this.left  = false;
        this.up    = false;
        this.down  = false;
    }

    this.KeyUp = function(KeyId)
    {
        //left
        if (KeyId == 37)
        {
            this.left = true;
        }
        //right
        if (KeyId == 39)
        {
            this.right = true;
        }
        //up
        if (KeyId == 38)
        {
            this.up = true;
        }
        //down
        if (KeyId == 40)
        {
            this.down = true;
        }
    }

    this.KeyDown = function(KeyId)
    {
        //left
        if (KeyId == 37)
        {
            this.left = false;
        }
        //right
        if (KeyId == 39)
        {
            this.right = false;
        }
        //up
        if (KeyId == 38)
        {
            this.up = false;
        }
        //down
        if (KeyId == 40)
        {
            this.down = false;
        }
    }

}

//add onkeydown e onkey up 
document.onkeyup   = onKeyUp;
document.onkeydown = onKeyDown;
document.onload    = start();

var keys = new Keys();

function onKeyUp(e)
{
    KeyId = (window.event) ? event.keyCode : e.keyCode;
    keys.KeyUp(KeyId);
    e.preventDefault();
}

function onKeyDown(e)
{
    KeyId = (window.event) ? event.keyCode : e.keyCode;
    keys.KeyDown(KeyId);
    e.preventDefault();
}


function start()
{
    setInterval('loop()', 30);
}
